﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VIA.Presentation.Contracts;
using VIA.Presentation;
using VIA.SiMoJi.Domain.Inspection;
using VIA.Foundation;
using VIA.Foundation.Services;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.DependencyInjection;
using Autofac.Core;
using VIA.SiMoJi.Presentation.View;

namespace VIA.SiMoJi.Presentation.ViewModel
{
    [ViewModel(typeof(IManualDebugginView))]
    internal class ManualDebuggingViewModel : ViewModel<IManualDebugginView>
    {
        protected IMessageService _messageService;
        protected IBusyService _busyService;
        protected IDispatcherService _dispatcherService;
        protected IShellService _shellService;
        protected IFileDialogService _dialogService;
        protected ICommandFactory _commandFactory;
        protected ILogger _logger;
        private IAxisDebugView _AxisDebugView;
        private AxisDebugViewModel _AxisDebugViewModel;
        public BuJinPiDai BuJinPiDai { get; }
        public GongLiaoStation GongLiaoStation { get; }
        public VisionStation VisionStation { get; }
        public BanYunStation BanYunStation { get; }
        public SiMoStation SiMoStation { get; }
        public NGXiaLiao NGXiaoLIaoSation { get; }
        public Feeder FeiDaStation1 { get; }
        public Feeder FeiDaStation2 { get; }
        #region Commands

        public IRelayCommand Command { get; }
        public IRelayCommand PiDaiDebugCommand { get; }

        #endregion

        public ManualDebuggingViewModel(IServiceProvider service, Inspector inspector)
        {
            _messageService = service.GetRequiredService<IMessageService>();
            _busyService = service.GetRequiredService<IBusyService>();
            _dispatcherService = service.GetRequiredService<IDispatcherService>();
            _shellService = service.GetRequiredService<IShellService>();
            _dialogService = service.GetRequiredService<IFileDialogService>();
            _commandFactory = service.GetRequiredService<ICommandFactory>();
            _AxisDebugView = service.GetRequiredService<IAxisDebugView>();
            _AxisDebugViewModel = _AxisDebugView.GetViewModel<AxisDebugViewModel>();
            _logger = service.GetRequiredService<ILogger<ManualDebuggingViewModel>>();
            BuJinPiDai = inspector.BuJinPiDai;
            GongLiaoStation = inspector.GongLiaoStation;
            VisionStation = inspector.VisionStation;
            BanYunStation = inspector.BanYunStation;
            SiMoStation = inspector.SiMoStation;
            NGXiaoLIaoSation = inspector.NGXiaLiao;
            //FeiDaStation1 = inspector.FeederLeft;
            //FeiDaStation2 = inspector.FeederRight;
            Command = _commandFactory.Create(CommandEx);
            PiDaiDebugCommand = _commandFactory.Create(PiDaiDebug);
        }

        private void PiDaiDebug()
        {
            _AxisDebugView.Axis = BuJinPiDai.Axis_PiDai1;
            _AxisDebugView.EditObject = BuJinPiDai.Axis_PiDai1;
            _AxisDebugView.Show();
        }

        private void CommandEx()
        {
            throw new NotImplementedException();
        }
    }
}
